﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using YJKMenuAssist.DataManagement;

namespace YJKMenuAssist.Utility
{
	public class Common
	{
		public static bool LessThan(double val1, double val2)
		{
			return val1 - val2 < -1E-09;
		}

		public static bool LessThan(double val1, double val2, double eps)
		{
			return val1 - val2 < -eps;
		}

		public static bool GreaterThan(double val1, double val2)
		{
			return val1 - val2 > 1E-09;
		}

		public static bool GreaterThan(double val1, double val2, double eps)
		{
			return val1 - val2 > eps;
		}

		public static bool IsEqual(double val1, double val2)
		{
			return !Common.LessThan(val1, val2) && !Common.LessThan(val2, val1);
		}

		public static bool IsEqual(double val1, double val2, double eps)
		{
			return !Common.LessThan(val1, val2, eps) && !Common.LessThan(val2, val1, eps);
		}

		public static bool Lessthan_Or_Equal(double val1, double val2)
		{
			return !Common.GreaterThan(val1, val2);
		}

		public static bool Lessthan_Or_Equal(double val1, double val2, double eps)
		{
			return !Common.GreaterThan(val1, val2, eps);
		}

		public static bool Greaterthan_Or_Equal(double val1, double val2)
		{
			return !Common.LessThan(val1, val2);
		}

		public static bool Greaterthan_Or_Equal(double val1, double val2, double eps)
		{
			return !Common.LessThan(val1, val2, eps);
		}

		public static CommandTableInfos Copy(CommandTableInfos commandTableInfos)
		{
			return new CommandTableInfos
			{
				CurrentTabName = commandTableInfos.CurrentTabName,
				TableInofList = commandTableInfos.TableInofList
			};
		}

		public static ImageSource ToImageSource(Icon icon)
		{
			return Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
		}

		public static void IniTreeView(CommandTableInfos commandTableInfos, TreeView treeView)
		{
			List<PropertyNodeItem> list = new List<PropertyNodeItem>();
			PropertyNodeItem propertyNodeItem = new PropertyNodeItem
			{
				DisplayName = "盈建科",
				ToolTip = "盈建科"
			};
			for (int i = 0; i < commandTableInfos.TableInofList.Count; i++)
			{
				TableInfos tableInfos = commandTableInfos.TableInofList[i];
				string tableName = tableInfos.TableName;
				if (tableInfos.Type == "HY")
				{
					PropertyNodeItem item = new PropertyNodeItem
					{
						DisplayName = tableName,
						ToolTip = tableName,
						Parent = "盈建科"
					};
					propertyNodeItem.Children.Add(item);
				}
			}
			list.Add(propertyNodeItem);
			PropertyNodeItem propertyNodeItem2 = new PropertyNodeItem
			{
				DisplayName = "REVIT",
				ToolTip = "REVIT"
			};
			for (int j = 0; j < commandTableInfos.TableInofList.Count; j++)
			{
				TableInfos tableInfos2 = commandTableInfos.TableInofList[j];
				string tableName2 = tableInfos2.TableName;
				if (tableInfos2.Type == "Revit")
				{
					PropertyNodeItem item2 = new PropertyNodeItem
					{
						DisplayName = tableName2,
						ToolTip = tableName2,
						Parent = "REVIT"
					};
					propertyNodeItem2.Children.Add(item2);
				}
			}
			list.Add(propertyNodeItem2);
			treeView.ItemsSource = list;
		}

		public static TOut TransReflection<TIn, TOut>(TIn tIn)
		{
			TOut tout = Activator.CreateInstance<TOut>();
			Type type = tIn.GetType();
			foreach (PropertyInfo propertyInfo in tout.GetType().GetProperties())
			{
				PropertyInfo property = type.GetProperty(propertyInfo.Name);
				if (property != null)
				{
					propertyInfo.SetValue(tout, property.GetValue(tIn));
				}
			}
			return tout;
		}

		public const double _epsDouble = 1E-09;

		public const double _epsPoint = 0.0001;

		public const double _epsAngle = 0.0001;
	}
}
